package org.dromara.app.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.bean.domain.HisGoodsOrderEvaluate;
import org.dromara.bean.domain.bo.HisGoodsBo;
import org.dromara.bean.domain.vo.HisGoodsOrderEvaluateVo;
import org.dromara.bean.domain.vo.HisGoodsVo;
import org.dromara.bean.mapper.HisGoodsOrderEvaluateMapper;
import org.dromara.bean.service.IHisGoodsService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品
 *
 * @author Lion Li
 * @date 2024-12-13
 */
@Validated
@RequiredArgsConstructor
@RestController
@SaIgnore
@RequestMapping("/app/goods")
public class AHisGoodsController extends BaseController {

    private final IHisGoodsService hisGoodsService;

    private final HisGoodsOrderEvaluateMapper hisGoodsOrderEvaluateMapper;


    /**
     * 查询商品列表
     */
    @GetMapping("/list")
    public TableDataInfo<HisGoodsVo> list(HisGoodsBo bo, PageQuery pageQuery) {
        return hisGoodsService.xcxQueryPageList(bo, pageQuery);
    }


    /**
     * 获取商品详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:goods:query")
    @GetMapping("/{id}")
    public R<HisGoodsVo> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable Long id) {
        return R.ok(hisGoodsService.queryById(id));
    }


    /**
     * 商品评价列表
     */
    @GetMapping("/evaluate/{goodsId}")
    public TableDataInfo<HisGoodsOrderEvaluateVo> evaluateInfo(@PathVariable Long goodsId, PageQuery pageQuery) {
        QueryWrapper<HisGoodsOrderEvaluate> lqw = new QueryWrapper<>();
        lqw.eq("e.goods_id", goodsId);
        lqw.eq("e.status", 101);
        lqw.orderByDesc("e.create_time");
        Page<HisGoodsOrderEvaluateVo> result = hisGoodsOrderEvaluateMapper.selectPageHisGoodsOrderEvaluateList(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }
}
